from selenium.webdriver.common.by import By

from base.LoginXpath import LoginBase
from base.ObjectMap import ObjectMap
from common.yaml_config import GetConf


class LoginPage(LoginBase, ObjectMap):

    def email_input_value(self, driver, input_value):
        email_xpath = self.email_input()
        return self.element_fill_value(driver, By.XPATH, email_xpath, input_value)

    def password_input_value(self, driver, input_value):
        password_xpath = self.password_input()
        return self.element_fill_value(driver, By.XPATH, password_xpath, input_value)

    def click_login(self, driver):
        button_xpath = self.login_button()
        return self.element_click(driver, By.XPATH, button_xpath)

    def login(self, driver, user):
        self.element_to_url(driver, "/login")
        username, password, enterprise = GetConf().get_user_profile(user)
        self.email_input_value(driver, username)
        self.password_input_value(driver, password)
        self.click_login(driver)
        return enterprise
